<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/plateform/common-js.jsp"%>
  <%@ include file="/common/plateform/common-css.jsp"%>
  <script src="${ctx}/common/plateform/base/utils/tools-upload.js"></script>
  <title>模板实例化设置</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- 以下是body主体内容的模块区域 -->
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- top start -->
  <%@include file="/common/plateform/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/plateform/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
      <div class="row">
        <div class="col-xs-12">
        
          <!------搜索  start ------->
          <form id="searchForm" class="form-horizontal">
				<input type="hidden" name="doCode" value="dymicSql"/>
				<input type="hidden" name="pageName" value="sysTemplate-list">
				<input type="hidden" name="formName" value="searchForm">
				<input type="hidden" name="sysTemplate.w_delStatus" value="F">
				<input type="hidden" name="sysTemplate.w_cateNo" value="${param.cateNo }">
				<input type="hidden" name="sysTemplate.w_templateId" value="${param.templateId}">
				<input type="hidden" name="orderBy" value="create_time desc">
			</form>
	     <!------- 搜索 end -------->
           
        <!------- 列表 start -------->
          <div class="col-xs-12" id="box-header-temp" style="display: none;">
          	<div class="box box-success">
	          <div class="box-header with-border">
                 <h3 class="box-title" >
                 　　　              <button  onclick="toAdd();" class="btn btn-success" type="button"><i class="fa fa-plus-circle"></i> 请先选择模板 </button>
                 </h3>
              </div>
           </div>
         </div>
         
         <div id="dataList-body" style="display:none;">
         
         </div>
           
        </div>
      </div>
    </section>
    <!-- Main end -->
  </div>
  <!-- /.content-wrapper -->
  <!-- foot start -->
  <%@include file="/common/plateform/foot.jsp" %>
  <!-- foot start -->
  

<div class="modal fade" id="my_modal_add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							×
						</button>
						<h4 class="modal-title">
							<font color="red">信息添加</font> 
						</h4>
					</div>

					<div class="modal-body">
						<form class="form-horizontal" role="form" id="addForm">
							<input type="hidden" id="addForm_formToken" name="formToken" >
							<input type="hidden" name="doCode" value="dymicSql"/>
							<input type="hidden" name="pageName"  value="sysTemplate-list">
							<input type="hidden" name="formName"  value="addForm">
							<input type="hidden" name="sysTemplate.delStatus" value="F">
							<input type="hidden" name="sysTemplate.cateId" value="${param.cateId}">
							<input type="hidden" name="sysTemplate.cateNo" value="${param.cateNo}">
							<input type="hidden" name="sysTemplate.cateName" value="${param.cateName}">
						
					        <div class="box-body" id="addForm_submitFormData">
					          <!-- Custom Tabs -->
					          <div class="nav-tabs-custom">
					            <div class="tab-content">
					              <div class="tab-pane active" id="tab_1">
					              
									<div class="form-group">
						                  <label class="col-sm-2 control-label" >模板名称</label>
						                  <div class="col-sm-4">
						                	<input type="text" id="addForm_templateName" readonly="readonly" name="sysTemplate.templateName" class="form-control" value="cateNo-list.inc" required placeholder="必填项" />
						                  </div>
						                  <label class="col-sm-2 control-label" >所属系统</label>
						                  <div class="col-sm-4">
						                	<input type="text" id="addForm_sysName" readonly="readonly" name="sysTemplate.sysName" class="form-control" value="sale" required placeholder="必填项" />
						                  </div>
							        </div>

									<div class="form-group">
						                  <label class="col-sm-2 control-label" >模板地址</label>
						                  <div class="col-sm-4">
						                	<input type="text" id="addForm_templateUrl" readonly="readonly" name="sysTemplate.templateUrl" class="form-control" value="coding/pages/" required placeholder="必填项" />
						                  </div>
						                  <label class="col-sm-2 control-label" >tab个数</label>
						                  <div class="col-sm-4">
						                	<input type="text" id="addForm_tabNum" readonly="readonly" name="sysTemplate.tabNum" value="1" class="form-control" required placeholder="必填项" />
						                  </div>
							        </div>

									<div class="form-group">
						                  <label class="col-sm-2 control-label" >工程名</label>
						                  <div class="col-sm-8">
						                	<input type="text" id="addForm_projectName" readonly="readonly" name="sysTemplate.projectName" class="form-control" value="plateform" required placeholder="必填项" />
						                  </div>
						            </div>

									<div class="form-group">
						                  <label class="col-sm-2 control-label" >生成地址</label>
						                  <div class="col-sm-8">
						                	<input type="text" id="addForm_codeUrl" name="sysTemplate.codeUrl" class="form-control" value="plateform/admin/sale" required placeholder="必填项" />
						                  </div>
							        </div>

									<div class="form-group">
						                  <label class="col-sm-2 control-label" >页面名称</label>
						                  <div class="col-sm-8">
						                	<input type="text" id="addForm_pageName" readonly="readonly" name="sysTemplate.pageName" class="form-control" value="" required placeholder="必填项" />
						                  </div>
							        </div>

									<div class="form-group">
						                  <label class="col-sm-2 control-label" >主对象</label>
						                  <div class="col-sm-4">
						                	<input type="text" id="addForm_mainObj" name="sysTemplate.mainObj" class="form-control" value="trp_product" required placeholder="必填项" />
						                  </div>
						                  <label class="col-sm-2 control-label" >主对象ID</label>
						                  <div class="col-sm-4">
						                	<input type="text" id="addForm_mainId" name="sysTemplate.mainId" class="form-control" value="proId" required placeholder="必填项" />
						                  </div>
							        </div>

					              </div>					             
					              <!-- /.tab-pane -->
					            </div>
					            <!-- /.tab-content -->
					          </div>
					          <!-- nav-tabs-custom -->
					        </div>
			                <div class="box-footer">
				                <button type="button" class="btn btn-success pull-left" onclick="cannel('add');">取消</button>
				                <button type="button" class="btn btn-danger pull-right" onclick="add('addForm');">提 交</button>
				            </div>
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  


</body>


<!-- 以下是template列表模板的模块区域 -->
<script type="text/template" id="dataList-template">
		<? for ( var i = 0; i < rows.length; i++) {?>

		<div class="col-xs-12">
	
          <div class="box box-warning box-body">
	          <div class="box-header with-border">
                 <h4><i class="fa fa-flag-o fx5"></i> <?=strUtil.doNull(rows[i].cateName,'')?> | <?=strUtil.doNull(rows[i].cateNo,'')?> | <span class="red f18"><?=strUtil.doNull(rows[i].templateDesc,'')?>模板设置</span> | <?=strUtil.doNull(rows[i].templateName,'')?></h4>
              </div>
              <div class="box-body form-horizontal">
					<div class="form-group col-sm-12">
						<i class="fa fa-info fx8"></i> 生成页面：<?=strUtil.doNull(rows[i].codeUrl,'')?>/<?=strUtil.doNull(rows[i].pageName,'')?>
						&nbsp;，<?=strUtil.doNull(rows[i].tabNum,'')?>个tab
						&nbsp;，主对象<?=strUtil.doNull(rows[i].mainObj,'')?>（<?=strUtil.doNull(rows[i].mainId,'')?>）
					</div>
					<div class="form-group col-sm-12">
						<div class="form-group col-sm-3">
							<button type="button" class="btn btn-warning btn-sm" onclick="setParams('<?=rows[i].templateId?>','<?=rows[i].templateName?>','<?=rows[i].projectName?>','<?=rows[i].pageName?>','<?=rows[i].codeUrl?>','<?=rows[i].templateUrl?>','<?=rows[i].sysName?>','<?=rows[i].cateNo?>');">① 定义标签</button>
						</div>
						<div class="form-group col-sm-3">
							<button type="button" class="btn btn-success btn-sm" onclick="toTempParam('<?=rows[i].templateId?>','<?=rows[i].cateId?>','<?=rows[i].cateNo?>','<?=rows[i].cateName?>');">② 标签属性设置</button>   
						</div>
						<div class="form-group col-sm-3">
							<button type="button" class="btn btn-danger btn-sm" onclick="createProject('<?=rows[i].templateId?>');"><i class="fa fa-podcast">生成页面</button>
						</div>
					</div>

		        </div>
            </div>
        </div>
   <?}?>  		
</script>

</html>

<!-- 以下是js模块区域 -->
<script>
var clickMenu = "template-list-instance";
var id,myPage,dataListId,searchFormId,isShowLog,tableSort,tableId;
myPage = 10;
dataListId = "dataList";
searchFormId = "searchForm";
tableSort = "sysTemplate";
tableId = "templateId";
isShowLog = true;

$(function () {
	//1、加载分页列表数据
	getTableData();
	//2、控制是否启用token
	//setToken();
	
	//请在下面补充其他初始化方法（如数据字典、页面加载数据等）
	//3、初始化数据字典
	DictUtil.getCommonDictData("select","#addForm_cateId","sysTemplate.cateId","doCode=dymicSql&modelTypes=s_trpCate","{value:'cateId',text:'cateName',other:'cateNo,cateType'}","${param.cateId}");
 });
var dateObject = $('.datepicker').datepicker( {
	language : 'zh-CN',
	//inline: true,
	todayBtn : "linked",
	format : "yyyy-mm-dd",
	autoclose: true
});
//读取（查询、编辑）数据
function toLoad(id,type){
	var paramLoadData = {"sysTemplate.w_templateId":id,"modelTypes":"s_"+tableSort};
	loadObj(type,paramLoadData);
}
function toDele(id){
	var index_submit = layer.confirm('您确定要删除信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		var paramLoadData = {"modelTypes":"d_sysTemplate","sysTemplate.w_templateId":id};
		//var paramLoadData = {"modelTypes":"u_sysTemplate","sysTemplate.delStatus":"T","sysTemplate.w_templateId":id};
		doDele(paramLoadData);
	});
}
//反显数据
function showData(type,myData){
	console.log(myData);
	if("view"==type){
		FormUtil.loadView("sysTemplate", myData);
		$("#my_modal_view").modal("show");
	}else if("edit"==type){
		//修改弹框时，初始化数据字典
		cleanData('editForm_submitFormData');
		DictUtil.getCommonDictData("select","#editForm_cateId","sysTemplate.cateId","doCode=dymicSql&modelTypes=s_trpCate","{value:'cateId',text:'cateName',other:'cateNo,cateType'}",myData.cateId);
		FormUtil.loadView("sysTemplate", myData);
		//FormUtil.fillData("#editForm", myData,"id");
		$("#w_"+tableId).val(myData.templateId);
		$("#my_modal_edit").modal("show");
	}
}

$(function () {
	$('#'+dataListId+' tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     id = $('tr.selected td').eq(0).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );
	
	
  });
//加载列表数据
function getTableData(){
	deleteAllRow(dataListId);
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFormId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFormId).serialize(),myPage),
		   dataType:'json',
		   success: function(myData){
		   if(isShowLog)console.log(myData);
		   if(myData.total==0){
			   $("#box-header-temp").show();
			   $("#dataList-body").hide();
		   }else{
			   $("#box-header-temp").hide();
			   $("#dataList-body").show();
		   }
			var data = baidu.template(dataListId+"-template",eval(myData));  
			$("#"+dataListId+"-body").html(data);
			  var option= {
					   ele:$("#"+dataListId+"-page")[0],
					   total:myData.total,
					   fn:getTableData,
					   url:common_list_url+"?"+$("#"+searchFormId).serialize()
				   }
				generatePages(option);
		   }
		});	
  }

//设置模态框隐藏事件 
$( '#my_modal_add' ).on( 'show.bs.modal' ,function(e){  
	setToken();
}); 
//清空数据
function cleanData(id){
	$('#'+id).find(".clean").val("");//按照样式清空；
}
//打开添加页面
function toAdd(){
	cleanData('addForm_submitFormData');//清空模态窗口内数据
	
	$("input[name='sysTemplate.pageName']").val("${param.cateNo}-list.jsp");
	
	$("#w_"+tableId).val("");
	$(".datepicker").val("");
	$('#my_modal_add').modal('show');
}

//获取对象值
function loadObj(type,paramData){
	$.ajax({
	    type:'get',
	   	url:common_info_url+"?doCode=dymicSql",
	    data: paramData,
	    async:false,
	    dataType:"json",
	    success: function(myData){
	    	showData(type,myData);
	  	}
	});	
}

//删除信息（逻辑删除）
function doDele(paramData){
	$.ajax({
	    type:"post",
	    url:common_submit_url+"?doCode=dymicSql",
	    data: paramData,
	    dataType:"json",
	    success: function(myData){
	    	var result = myData.flag;
	    	if(result=="T"){
	    		layer.alert("删除操作成功");
	    		refresh();
	    	}
	  	}
	});	
}

/**
 * 新增表单数据提交
 * @param formId
 */
function add(formId){
	var index_submit = layer.confirm('您确定要提交信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		$.ajax({
		    type:"post",
		    url:common_submit_url,
		    data:$("#"+formId).serialize(),
		    dataType:"json",
		    success: function(myData){
		    	//console.log(myData);
		    	if(myData.flag=="T"){
		    		layer.alert("数据保存成功");
		    		$("#my_modal_add").modal("hide");
		    	}else{
		    		layer.alert(myData.msg);
		    	}
		    	refresh();
		  	}
		});	
	});
}

/**
 * 修改表单数据提交
 * @param formId
 */
function edit(formId){
	var index_submit = layer.confirm('您确定要提交信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		$.ajax({
		    type:"post",
		    url:common_submit_url,
		    data:$("#"+formId).serialize(),
		    dataType:"json",
		    success: function(myData){
		    	//console.log(myData);
		    	if(myData.flag=="T"){
		    		layer.alert("数据保存成功");
		    		$("#my_modal_edit").modal("hide");
		    	}else{
		    		layer.alert(myData.msg);
		    	}
		    	refresh();
		  	}
		});	
	});
}

//关闭win
function cannel(type){
	if(strUtil.isNull(type)){
		$('#my_modal_add').modal('hide');
	}else{
		$('#my_modal_'+type).modal('hide');
	}
}

function refresh(){
	getTableData();
}


function setToken(){
	$.ajax({
	    type:'get',
	    url:'/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	console.log(myData);
			$('#addForm_formToken').val(myData);
			$('#editForm_formToken').val(myData);
	  	}
	});	
}



function setParams(templateId,templateName,projectName,pageName,codeUrl,templateUrl,sysName,cateNo){
	window.location.href="${page_admin}/template/template-list-instance-setObj?templateId="+templateId+"&templateName="+templateName+"&projectName="+projectName+"&pageName="+pageName+"&codeUrl="+codeUrl+"&templateUrl="+templateUrl+"&sysName="+sysName+"&cateNo="+cateNo;
}

function createProject(templateId){
	var index_load = layer.msg("正在生成中。。。", {shade: false,offset: '220px'});
	  var this_url ="${ctx}/common/coding/buildProjects";
	  $.ajax({
		  type:'post',
		  url:this_url,
		  data:{"templateId":templateId},
		  cache: false,
		  async:false,
		  dataType:'json',
		   success: function(myData){ alert(myData.msg); layer.close(index_load);}
	  });
}

function toTempParam(templateId,cateId,cateNo,cateName){
	//window.location.href="${page_admin}/sale/sale-trpCate-trpTemplate?cateNo="+cateNo+"&cateId="+cateId+"&cateName="+cateName;
	window.location.href="${page_admin}/template/template-list-instance-setObjCol?templateId="+templateId+"&cateNo="+cateNo+"&cateId="+cateId+"&cateName="+cateName;	
}
</script>



